
import { createRouter, createWebHistory, createWebHashHistory } from 'vue-router'
import {useUserStore} from '@/stores'
import routes from './routes'


const router = createRouter({
  // 历史模式
  history: createWebHistory(import.meta.env.BASE_URL),
  routes
})
// 页面拦截 全局前置导航守卫 vue3没有next参数
router.beforeEach((to, from) => {
  document.title=`在线问诊-${to.meta.title || ''}`
  const store = useUserStore()
  const whiteList = ['/login']
  // console.log('数据',store.userData.token)
  if (!store.userData.token && !whiteList.includes(to.path)) return '/login'
})
export default router
